package com.ruoyi.web.controller.workSafetyStandardization.rule;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workSafetyStandardization.domain.AccidentJudge;
import com.ruoyi.workSafetyStandardization.service.IAccidentJudgeService;
import com.ruoyi.workSafetyStandardization.service.IGradeRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评分-重大事故隐患判定Controller
 *
 * @author pengjie
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/secure/securerule/gradeJudge")
public class AccidentJudgeController extends BaseController
{
    @Autowired
    private IAccidentJudgeService accidentJudgeService;
    @Autowired
    private IGradeRuleService gradeRuleService;

    /**
     * 查询评分-重大事故隐患判定列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeJudge:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccidentJudge accidentJudge, @Param("pageSize") String pageSize, @Param("pageNum") String pageNum)
    {
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<AccidentJudge> list = accidentJudgeService.selectAccidentJudgeList(accidentJudge);
        return getDataTable(list);
    }

    /**
     * 导出评分-重大事故隐患判定列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeJudge:export')")
    @Log(title = "评分-重大事故隐患判定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccidentJudge accidentJudge)
    {
        List<AccidentJudge> list = accidentJudgeService.selectAccidentJudgeList(accidentJudge);
        ExcelUtil<AccidentJudge> util = new ExcelUtil<AccidentJudge>(AccidentJudge.class);
        util.exportExcel(response, list, "评分-重大事故隐患判定数据");
    }

    /**
     * 获取评分-重大事故隐患判定详细信息
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeJudge:query')")
    @GetMapping(value = "/{accidentJudgeId}")
    public AjaxResult getInfo(@PathVariable("accidentJudgeId") String accidentJudgeId)
    {
        return success(accidentJudgeService.selectAccidentJudgeByAccidentJudgeId(accidentJudgeId));
    }

    /**
     * 新增评分-重大事故隐患判定
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeJudge:add')")
    @Log(title = "评分-重大事故隐患判定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccidentJudge accidentJudge)
    {
        accidentJudge.setAccidentJudgeId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(accidentJudgeService.insertAccidentJudge(accidentJudge));
    }

    /**
     * 修改评分-重大事故隐患判定
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeJudge:edit')")
    @Log(title = "评分-重大事故隐患判定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccidentJudge accidentJudge)
    {
        return toAjax(accidentJudgeService.updateAccidentJudge(accidentJudge));
    }

    /**
     * 删除评分-重大事故隐患判定
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:gradeJudge:remove')")
    @Log(title = "评分-重大事故隐患判定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accidentJudgeIds}")
    public AjaxResult remove(@PathVariable String[] accidentJudgeIds)
    {
        return toAjax(accidentJudgeService.deleteAccidentJudgeByAccidentJudgeIds(accidentJudgeIds));
    }
}
